package com.feihao.zhou.demo;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;
import java.util.Random;

public class IteratorTest {
    public static void main(String[] args) {
        Collection<Integer> collection = new ArrayList<Integer>();
        collection.add(78);
        collection.add(33);
        collection.add(22);
        collection.add(11);

        //创建迭代器对象：
        Iterator<Integer> it = collection.iterator();
        //使用迭代器遍历：
       /* while (it.hasNext()){//如果有元素：
            Integer integer = it.next();
            System.out.println(integer);
        }*/

        //使用迭代器删除集合指定元素：
        /*while (it.hasNext()){
            Integer i = it.next();
            if (33==i){
                it.remove();
            }
        }*/

        for (Iterator<Integer> it1 = collection.iterator(); it.hasNext(); ) {
            int aValue = it.next();
            if(33==aValue) {
                it.remove();
            }
        }

        System.out.println(collection);

        ArrayList<Integer> list = new ArrayList<>();


        /*Collection<Integer> integers = new ArrayList<>();*/
        Random random = new Random();
        for (int i = 0; i < 30; i++) {

            list.add(i);
        }

//        boolean remove = list.remove());
//        System.out.println(remove);


       /* //使用for循环遍历测试时间：
        long start = System.currentTimeMillis();
        *//*for (int i = 0; i < list.size(); i++) {
            System.out.println(list.get(i));
        }*//*

        for (Integer integer : list) {
            if (integer==2);
            list.remove(2);
        }

        System.out.println(list);

        long end = System.currentTimeMillis();

        System.out.println(end-start);*/
    }
}
